package com.atstudy.reflect;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.stream.Stream;

/**
 * @version v1.0
 * @description:
 * @author: admin
 * @date: 2023/1/10 10:05
 * @copyright: 博为峰
 */
public class RefDemo03 {
    public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
        Class<?> aClass = Class.forName("com.atstudy.reflect.Student");
        Method[] methods = aClass.getDeclaredMethods();

        Stream<Method> stream = Arrays.stream(methods);

//        stream.forEach(System.out::println);

        Constructor<?> constructor = aClass.getConstructor(String.class, int.class, String.class);

        Student student = (Student) constructor.newInstance("张三", 20, "男");

        Method method = aClass.getMethod("m2", String.class);

        method.invoke(student, "bwf");
    }

}
